/*
 * Created on May 13, 2004
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * http//www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is MAPONTO.
 *
 * The Initial Developer of the Original Code is University of Toronto. Portions
 * created by University of Toronto are Copyright (C) 2004.  All Rights Reserved.
 *
 * MAPONTO was developed by Knowledge Management Lab
 * (http//www.cs.toronto.edu/km) at the University of Toronto Department of 
 * Computer Science. Current information about MAPONTO can be obtained at 
 * http//resi.ai.toronto.edu:8080
 *
 */

 /*
  * Contributor(s): Yuan An yuana@cs.toronto.edu
 */
/*
 * Adopted from: Stephen Montgomery
 * Contact: smontgom@bcgsc.bc.ca
 *
 * For Canadian Bioinformatics Developing the Tools Workshop 2004
 * License: GPL
 */
package main.logger;

/**
 * DESCRIPTION:
 * LoggerSetup starts the log4j logging utilities for this application.
 * It must be called on application start-up to get the benefit of the 
 * log.XXX() statements. 
 * 
 * @author Yuan An
 */
import java.net.URL;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
import org.apache.log4j.Level;

public class LoggerSetup {

  /**
   * @param The class logger
   */
  private static final Logger log = Logger.getLogger(LoggerSetup.class);

  /**
   * Configure logger.
   */
  static {
	try {
	  URL log4j_resource = LoggerSetup.class.
		  getResource(
		  "log4j.pwt.xml");
		  //Load logging configuration from the CLASSPATH
		  
	  if (log4j_resource == null) {
		throw new Exception("Could not load log4j configuration");
	  }
	  DOMConfigurator.configure(log4j_resource);
	  //Configure logging using configuration file
	}
	catch (Exception e) {
	  BasicConfigurator.configure();
	  //Use default configuration
	  log.setLevel(Level.DEBUG);
	  
	  log.warn(
		  "Could NOT load \"log4j.pwt.xml\" - Make sure it is in the CLASSPATH",
		  e);
	}
  }

  public static void enable() {
	//does nothing but ensure that the log resource has been loaded via the class
	//loader.
  }
}

